package com.li.onjava8.concurrent.cf.task;

/**
 * @author li
 * @date 2023/11/1 9:45
 */
public class Breakable {
    String id;
    private int failcount;

    public Breakable(String id, int failcount) {
        this.id = id;
        this.failcount = failcount;
    }

    @Override
    public String toString() {
        return "Breakable_" + id + " [" + failcount + "]";
    }

    //failcount为正时，每次将对象传递给work()方法可减少failcount。当它为零时，work()会引发异常。
    public static Breakable work(Breakable b) {
        if (--b.failcount == 0) {
            System.out.println("Throwing Exception for " + b.id + "");
            throw new RuntimeException("Breakable" + b.id + " failed");
        }
        System.out.println(b);
        return b;
    }


}
